//
//  MKCGRect.h
//  MKUI
//
//  Created by sushangjin on 2018/11/5.
//  Copyright © 2018 sushangjin. All rights reserved.
//

#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface MKCGRect:NSObject
@property(nonatomic,assign) CGRect rect;
- (id)initWithRect:(CGRect)rect;
+ (MKCGRect *)rect:(CGRect)rect;

@property(nonatomic,assign) CGPoint center;

@property(nonatomic,assign) CGFloat minX;
@property(nonatomic,assign) CGFloat midX;
@property(nonatomic,assign) CGFloat maxX;

@property(nonatomic,assign) CGFloat minY;
@property(nonatomic,assign) CGFloat midY;
@property(nonatomic,assign) CGFloat maxY;

@property(nonatomic,assign) CGPoint origin;
@property(nonatomic,assign) CGFloat x;
@property(nonatomic,assign) CGFloat y;
@property(nonatomic,assign) CGSize size;
@property(nonatomic,assign) CGFloat width;
@property(nonatomic,assign) CGFloat height;

typedef CGFloat(^MKCGRectB)(CGFloat);
@property(nonatomic,readonly) MKCGRectB percentX;
@property(nonatomic,readonly) MKCGRectB percentY;

#pragma mark - 链式调用

+ (MKCGRect *(^)(CGRect rect))rect;
+ (MKCGRect *(^)(CGFloat x,CGFloat y,CGFloat width,CGFloat height))make;

typedef MKCGRect * __nonnull (^MKCGRectR)(CGRect);
@property(nonatomic,readonly) MKCGRectR centerToRect;

@property(nonatomic,readonly) MKCGRectR minXToRect;
@property(nonatomic,readonly) MKCGRectR midXToRect;
@property(nonatomic,readonly) MKCGRectR maxXToRect;
@property(nonatomic,readonly) MKCGRectR minYToRect;
@property(nonatomic,readonly) MKCGRectR midYToRect;
@property(nonatomic,readonly) MKCGRectR maxYToRect;

@property(nonatomic,readonly) MKCGRectR rectToRect;

typedef MKCGRect * __nonnull (^MKCGRectF)(CGFloat);
@property(nonatomic,readonly) MKCGRectF minXToValue;
@property(nonatomic,readonly) MKCGRectF midXToValue;
@property(nonatomic,readonly) MKCGRectF maxXToValue;
@property(nonatomic,readonly) MKCGRectF minYToValue;
@property(nonatomic,readonly) MKCGRectF midYToValue;
@property(nonatomic,readonly) MKCGRectF maxYToValue;

@property(nonatomic,readonly) MKCGRectF xToValue;
@property(nonatomic,readonly) MKCGRectF yToValue;
@property(nonatomic,readonly) MKCGRectF widthToValue;
@property(nonatomic,readonly) MKCGRectF heightToValue;
typedef MKCGRect * __nonnull (^MKCGRectS)(CGSize);
@property(nonatomic,readonly) MKCGRectS sizeToValue;

typedef MKCGRect * __nonnull (^MKCGRectE)(CGRect,CGFloat);//边与rect的padding值
@property(nonatomic,readonly) MKCGRectE minXToEdge;//left-padding
@property(nonatomic,readonly) MKCGRectE maxXToEdge;//right-padding
@property(nonatomic,readonly) MKCGRectE minYToEdge;//top-padding
@property(nonatomic,readonly) MKCGRectE maxYToEdge;//bottom-padding
@end

@interface MKCGRect(Scale)

/**
 *  如果originSize的尺寸超过maxSize，则等比例缩放originSize直到宽高都不超过maxSize
 *
 *  @param originSize 原始的尺寸
 *  @param maxSize    最大尺寸
 *
 *  @return 等比例缩放后的尺寸
 */
+ (CGSize)scaleSize:(CGSize)originSize aspectFitToMaxSize:(CGSize)maxSize;

/// 将originSize，等比例缩放到maxSize（某一边值与maxSize一致）
/// @param originSize 原始的尺寸
/// @param maxSize 最大尺寸
+ (CGSize)scaleSize:(CGSize)originSize aspectFitToSize:(CGSize)maxSize;

/**
 根据contentMode属性,计算从fromRect缩放平移到toRect的仿射变换矩阵

 @param fromRect 源区域
 @param toRect 目标区域
 @param contentMode contentMode值,contentMode中的Top定义为CGRectGetMinY,Left定义为CGRectGetMinX.即为UIKit坐标系下CGRect中关于Top,Left的定义
 @return 变换矩阵
 */
+ (CGAffineTransform)transformRect:(CGRect)fromRect scaleTo:(CGRect)toRect contentMode:(UIViewContentMode)contentMode;
@end
NS_ASSUME_NONNULL_END
